﻿using ERP.ERPSystem.ProductionSystem;
using ERP.ERPSystem.ProductionSystem.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace ERP.Web.Controllers.ProductionSystem
{
    /// <summary>
    /// 车间设置控制器
    /// </summary>
    [Route("Workshop")]
    public class WorkshopController : Controller
    {
        private readonly IWorkshopServer _workshopServer;

        /// <summary>
        /// 构造函数，注入车间应用服务
        /// </summary>
        /// <param name="workshopServer">车间服务实例</param>
        public WorkshopController(IWorkshopServer workshopServer)
        {
            _workshopServer = workshopServer;
        }

        /// <summary>
        /// 返回车间管理的主视图页面
        /// </summary>
        /// <returns>WorkshopIndex.cshtml 视图</returns>
        [HttpGet("Index")]
        public IActionResult WorkshopIndex()
        {
            return View();
        }

        /// <summary>
        /// (API) 获取车间分页列表数据
        /// </summary>
        /// <param name="input">从查询字符串(Query String)中绑定的查询参数</param>
        /// <returns>车间的分页结果</returns>
        [HttpGet("api/list")]
        public Task<PagedResultDto<WorkshopDTO>> GetListAsync([FromQuery] GetWorkshopInputDto input)
        {
            return _workshopServer.GetListAsync(input);
        }

        /// <summary>
        /// (API) 根据ID获取单个车间信息
        /// </summary>
        /// <param name="id">车间ID</param>
        /// <returns>单个车间信息</returns>
        [HttpGet("api/get")]
        public Task<WorkshopDTO> GetAsync(int id)
        {
            return _workshopServer.GetAsync(id);
        }

        /// <summary>
        /// (API) 创建新车间
        /// </summary>
        /// <param name="input">从请求体(Body)中绑定的车间创建信息</param>
        /// <returns>创建后的车间信息</returns>
        [HttpPost("api/create")]
        public Task<WorkshopDTO> CreateAsync([FromBody] CreateUpdateWorkshopDto input)
        {
            return _workshopServer.CreateAsync(input);
        }

        /// <summary>
        /// (API) 更新车间信息
        /// </summary>
        /// <param name="id">从URL中获取的车间ID</param>
        /// <param name="input">从请求体(Body)中绑定的车间更新信息</param>
        /// <returns>更新后的车间信息</returns>
        [HttpPut("api/update/{id}")]
        public Task<WorkshopDTO> UpdateAsync(int id, [FromBody] CreateUpdateWorkshopDto input)
        {
            return _workshopServer.UpdateAsync(id, input);
        }

        /// <summary>
        /// (API) 删除单个车间
        /// </summary>
        /// <param name="id">从URL中获取的车间ID</param>
        [HttpDelete("api/delete/{id}")]
        public Task DeleteAsync(int id)
        {
            return _workshopServer.DeleteAsync(id);
        }

        /// <summary>
        /// (API) 批量删除车间
        /// </summary>
        /// <param name="ids">从请求体(Body)中获取的要删除的车间ID列表</param>
        [HttpPost("api/batch-delete")]
        public Task DeleteManyAsync([FromBody] IEnumerable<int> ids)
        {
            return _workshopServer.DeleteManyAsync(ids);
        }
    }
}
